import random
caculate = {}#字典存储题目及答案（算式：结果）
accuracy = 0.0#准确率 = (total - wrong)/total 

def operator():#随机生成运算符
    n = random.randint(1,4)
    if n== 1:
        return '+'
    elif n==2:
        return '-'
    elif n == 3:
        return '*'
    else :
        return '/'
    
def generater(total):#生成算式
    text = ""#字符串形式存储算式
    count = 0#算式个数
    while(count<total):
        A = random.randint(0,100)#运算数1
        B = random.randint(0,100)#运算数2
        C = random.randint(0,100)#运算数3
        operator_1 = operator()#运算符1
        operator_2 = operator()#运算符2
        if operator_1 == '/':#筛选第一个除号出现时的不合法情况
            if B == 0:
                continue
            if operator_2 == '*' and C == 0:
                continue
            if A % B != 0:
                continue
        if operator_2 == '/':#筛选第二个除号出现时的不合法情况
            if C==0:
                continue
            if B % C != 0:
                continue
        text = str(A) + operator_1 + str(B) + operator_2 + str(C)#拼合算式
        
        result = int(eval(text))#计算结果
        if result > 100 or result < 0:#根据计算结果范围筛选
            continue
        count += 1
        caculate[text] = result#存入字典中
def showTheaccuracy(wrong,total):#展示错误率
    print("Your accuracy is:",(total-wrong)/total*100,"%")

def test():#出题测试
    kase = 0#题目编号
    wrong = 0;#错误数目
    for i in caculate:
        kase += 1
        print(kase,':',i,'=',end = '\n')
        c = int(input("Your answer:"))
        if c == caculate[i]:
            print("You are right!\n",)
        else:
            wrong += 1
            print("You are Wrong! the true answer is %d\n"%caculate[i])
    return wrong
        
if __name__ == "__main__":
    total = int(input("输入题目数量:"))#自定义题目数量
    generater(total)
    wrong = test()
    showTheaccuracy(wrong,total)
    